<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <script src="../../js/load.js"></script>
</head>

<body>
<div class="layui-fluid">
    <div class="flexrow">
        <div class="layui-panel list-container">
            <div class="list-search-container">
                <button class="layui-btn layui-btn-sm" onclick="HandleAdd()"><i
                        class="layui-icon layui-icon-upload-circle layui-font-12"></i>新建分类
                </button>
            </div>
            <table class="layui-table" lay-data="{id: 'datagrid',height:'full'}" lay-filter="datagrid">
                <thead>
                <tr>
                    <th lay-data="{field:'groupName'}">分类名称</th>
                    <th lay-data="{field:'sortNum',width:80,align:'center'}">排序</th>
                    <th lay-data="{fixed: 'right', width:180, align:'center', toolbar: '#op'}">操作</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="op">
    <button class="layui-btn layui-btn-sm" lay-event="HandleEdit"><i
            class="layui-icon layui-icon-edit layui-font-12"></i>编辑
    </button>
    <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="HandleDelete"><i
            class="layui-icon layui-icon-delete layui-font-12"></i>删除
    </button>
</script>
</html>
<script>
    $(function () {
        layui.use('laytpl', function () {
        })
        BindTableData();
    })

    function BindTableData() {
        var param = {

        }
        BindTable("datagrid", "api/group/list", param, function (result) {

        }, false);
    }


    function HandleAdd() {
        OpenDialog('新建分类', 'pages/group/group_add.html', 600, 400 , function () {
            BindTableData();
        })
    }

    function HandleEdit(RowData) {
       OpenDialog('编辑分类', 'pages/group/group_edit.html?groupID=' + RowData.groupID, 600, 400 , function () {
            BindTableData();
        })
    }

    function HandleDelete(RowData) {
        OpenConfirm('确认删除？', function () {
            var param = {
                groupID: RowData.groupID,
            }
            HttpPost(JSON.stringify(param), 'api/group/delete', function (result) {
                if (result.code == 0) {
                    OpenSuccessMessage("删除成功")
                    BindTableData();
                } else {
                    OpenFail(result.msg);
                }
            })
        })
    }
</script>